package bar.dark.lee.stats;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.RadioButton;
import bar.dark.lee.R;
import bar.dark.lee.SuperActivity;
import bar.dark.lee.common.BDUtil;
import bar.dark.lee.common.DBSQLite;
import bar.dark.lee.setting.TipInfoActivity;
import bar.dark.lee.setting.TipsActivity;

public class StatsAssetActivity extends SuperActivity
{
	public final static String TYPE_FLAG = "TYPE_flag";
	public final static String ASSET_FLAG = "asset_flag";
	
	private DBSQLite sql;
	
	private View outView;
	private View inView;
	private View moveView;
	
	private RadioButton outRadioButton;
	private RadioButton inRadioButton;
	private RadioButton moveRadioButton;
	
	private View bankView;
	private View checkView;
	private View creditView;
	private View realView;
	
	private RadioButton bankRadioButton;
	private RadioButton checkRadioButton;
	private RadioButton creditRadioButton;
	private RadioButton realRadioButton;
	
	private Button searchButton;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.stats_asset_activity);
		
		sql = DBSQLite.getInstance(superContext);
		
		setTitle("자산 / 타입 선택");
		
		setFindView();
		setOnClickListener();
		
		outRadioButton.setChecked(true);
		bankRadioButton.setChecked(true);
	}
	
	private void setFindView()
	{
		outView = findViewById(R.id.statsAssetOutMoneyButton);
		inView = findViewById(R.id.statsAssetInMoneyButton);
		moveView = findViewById(R.id.statsAssetMoveMoneyButton);
		
		outRadioButton = (RadioButton) findViewById(R.id.statsAssetOutMoneyCheckBox);
		inRadioButton = (RadioButton) findViewById(R.id.statsAssetInMoneyCheckBox);
		moveRadioButton = (RadioButton) findViewById(R.id.statsAssetMoveMoneyCheckBox);
		
		bankView = findViewById(R.id.statsAssetBankBookButton);
		checkView = findViewById(R.id.statsAssetCheckCardButton);
		creditView = findViewById(R.id.statsAssetCreditCardButton);
		realView = findViewById(R.id.statsAssetRealMoneyButton);
		
		bankRadioButton = (RadioButton) findViewById(R.id.statsAssetBankBookRadioButton);
		checkRadioButton = (RadioButton) findViewById(R.id.statsAssetCheckCardRadioButton);
		creditRadioButton = (RadioButton) findViewById(R.id.statsAssetCreditCardRadioButton);
		realRadioButton = (RadioButton) findViewById(R.id.statsAssetRealMoneyRadioButton);
		
		searchButton = (Button) findViewById(R.id.statsAssetSelectButton);
	}
	
	private void setOnClickListener()
	{
		outView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				outRadioButton.setChecked(true);
				inRadioButton.setChecked(false);
				moveRadioButton.setChecked(false);
			}
		});
		
		inView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				outRadioButton.setChecked(false);
				inRadioButton.setChecked(true);
				moveRadioButton.setChecked(false);
			}
		});
		
		moveView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				outRadioButton.setChecked(false);
				inRadioButton.setChecked(false);
				moveRadioButton.setChecked(true);
			}
		});
		
		bankView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				bankRadioButton.setChecked(true);
				checkRadioButton.setChecked(false);
				creditRadioButton.setChecked(false);
				realRadioButton.setChecked(false);
			}
		});
		
		checkView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				bankRadioButton.setChecked(false);
				checkRadioButton.setChecked(true);
				creditRadioButton.setChecked(false);
				realRadioButton.setChecked(false);
			}
		});
		
		creditView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				bankRadioButton.setChecked(false);
				checkRadioButton.setChecked(false);
				creditRadioButton.setChecked(true);
				realRadioButton.setChecked(false);
			}
		});
		
		realView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				bankRadioButton.setChecked(false);
				checkRadioButton.setChecked(false);
				creditRadioButton.setChecked(false);
				realRadioButton.setChecked(true);
			}
		});
		
		searchButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent(StatsAssetActivity.this, StatsCategoryActivity.class);
				intent.putExtra(StatsActivity.STATS_CATEGORY_FLAG, StatsActivity.STATS_ASSET_MANAGER);
				
				if (outRadioButton.isChecked())
				{
					intent.putExtra(TYPE_FLAG, 0);
				}
				else if (inRadioButton.isChecked())
				{
					intent.putExtra(TYPE_FLAG, 1);
				}
				else if (moveRadioButton.isChecked())
				{
					intent.putExtra(TYPE_FLAG, 2);
				}
				
				if (bankRadioButton.isChecked())
				{
					intent.putExtra(ASSET_FLAG, 0);
				}
				else if (checkRadioButton.isChecked())
				{
					intent.putExtra(ASSET_FLAG, 1);
				}
				else if (creditRadioButton.isChecked())
				{
					intent.putExtra(ASSET_FLAG, 2);
				}
				else if (realRadioButton.isChecked())
				{
					intent.putExtra(ASSET_FLAG, 3);
				}
				
				startActivity(intent);
			}
		});
	}

	@Override
	protected void tipButton()
	{
		Intent intent = new Intent(this, TipInfoActivity.class);
		intent.putExtra(TipsActivity.TIP_REQUEST_KEY, TipsActivity.TIP_STATS);
		startActivity(intent);
	}
}
